package com.example.controller;

import com.example.pojo.Privilege;
import com.example.pojo.User;
import com.example.service.PrivilegeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author 二七和夭夭
 * @email 2646498606@qq.com
 * @date 2022/8/24 14:45
 */
@Controller
@RequestMapping("/home")
public class HomeController {
    @Autowired
    private PrivilegeService privilegeService;

    @RequestMapping("/left.do")
    public String leftPage(HttpServletRequest req, Model model) {
        //加入登录用户
        User user = (User)req.getSession().getAttribute("loginUser");
        //加入页面中
        model.addAttribute("loginUser", user);

        //权限列表信息
        List<Privilege> privilegeTopList = privilegeService.selectRootPrivilege();
        model.addAttribute("privilegeTopList", privilegeTopList);

        return "/jsp/home/left.jsp";
    }

    @RequestMapping("/right.do")
    public String rightPage(HttpServletRequest req, Model model) {
        //加入登录用户
        User user = (User)req.getSession().getAttribute("loginUser");
        //加入页面中
        model.addAttribute("loginUser", user);
        return "/jsp/home/right.jsp";
    }

    @RequestMapping("/bottom.do")
    public String bottomPage(HttpServletRequest req, Model model) {
        //加入登录用户
        User user = (User)req.getSession().getAttribute("loginUser");
        //加入页面中
        model.addAttribute("loginUser", user);
        return "/jsp/home/bottom.jsp";
    }

    @RequestMapping("/top.do")
    public String topPage(HttpServletRequest req, Model model) {
        //加入登录用户
        User user = (User)req.getSession().getAttribute("loginUser");
        //加入页面中
        model.addAttribute("loginUser", user);
        return "/jsp/home/top.jsp";
    }
}
